<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>药品分发（应急）</title>
    <!-- jquery - boot -库文件 -->
    <script src="__PUBLIC__/script/jquery.1.11.1.js"></script>
    <script src="__PUBLIC__/script/bootstrap.min.js"></script>
    <!-- Bootstrap -->
    <link href="__PUBLIC__/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap -->
    <!-- font awesome -->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/plugins/FontAwesome/css/font-awesome.min.css">
    <script src="__PUBLIC__/script/common.js"></script>
    <!--easyui包含文件-->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/plugins/easyui1.5.3/themes/material/easyui.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/plugins/easyui1.5.3/themes/icon.css">
    <script type="text/javascript" src="__PUBLIC__/plugins/easyui1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/plugins/easyui1.5.3/locale/easyui-lang-zh_CN.js"></script>
    <!--layer-->
    <script type="text/javascript" src="__PUBLIC__/plugins/layer/layer.js"></script>
    <!-- 自定义 css -->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/reset.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/common.css">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/style.css">
    <!-- end easyui -->
    <!--图片放大镜-->
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/magnifier.css">
    <script type="text/javascript" src="__PUBLIC__/script/magnifier.js"></script>
    <!--图片放大镜-->
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="__PUBLIC__/script/html5shiv.js"></script>
    <script src="__PUBLIC__/script/respond.js"></script>
    <![endif]-->
</head>

<body>
    <include file="Public/header" />
    <!-- indexmain -->
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12 mainbox" id="mainbox">
                <!--menubegin-->
                <div class="datamenubox" id="leftmenu">
                    <div class="menuhead">药品分发（应急）</div>
                    <!-- treein -->
                    <div class="treein" id="menuin">
                        <ul class="list-group smenu">
                            <volist name="menulist" id="vo">
                                <a href="{:U($vo[url])}"><li class="list-group-item" id="{$vo.url}"><i class="fa fa-angle-right"></i>{$vo.name}</li></a>
                            </volist>
                        </ul>
                    </div>
                </div>
                <!--menuend-->
                <!--mainboxbegin-->
                <div class="col-md-12 rights" id="right">
                    <!-- 位置导航 -->
                    <ol class="breadcrumb">
                        <li class="active">首页</li>
                        <li class="active">药品领取</li>
                        <li class="active">药品分发（应急）</li>
                    </ol>
                    <!-- 筛选 -->
                    <div class="searchitem">
                        <div class="row">
                            <div class="col-md-12">
                                <input class="easyui-combobox" name="q_lqr" id="q_lqr" style="width:200px" data-options="label:'领取人：',valueField:'id',textField:'text',panelHeight:'180'"> 
                                <input class="easyui-combobox" name="q_sflq" id="q_sflq" style="width:200px" data-options="label:'是否领取：',valueField:'id',textField:'text',panelHeight:'180'">                                               
                                &nbsp;&nbsp;&nbsp;&nbsp;<button class="btn btn-danger" id="querybtn">查询</button>
                            </div>
                        </div>
                        <!-- end 筛选 -->
                    </div>
                    <!-- listtable -->
                    <div>
                        <!-- gridview row -->
                        <table id="dg"></table>
                        <!-- end gridview row -->
                    </div>
                    <!--mainboxend-->
                </div>
            </div>
        </div>
        <!-- indexmain end -->
        <!-- modals -->
        <div id="w" class="easyui-window" title="应急药剂申请记录/药剂分发记录" data-options="modal:true,closed:true" style="width:500px;height:630px;padding:15px;display:none;">
            <div class="panel panel-default">
                <div class="panel-heading">药品申请明细</div>
                <table class="table">
                    <th>名称</th><th>剂量（L） </th><th>剩余剂量（L） </th>
                    <tbody  id="lqmx">               
                    </tbody>
                </table>
            </div>
            <div class="blank10"></div>
            <div class="panel panel-default">
                <div class="panel-heading">药品分发记录</div>
                <style>
                    .ffjl{
                        font-size: 13px;
                        margin: 5px;
                    }
                </style>
                <div id="jl" style="height: 200px;overflow-y: scroll;">
                    
                </div>
            </div>
            <div class="blank10"></div>
            <input type="hidden" id="hidid" name="hidid" />
            <div class="btnin">
                <a class="btn btn-info" id="submits">分发完成</a>&nbsp;
                <a class="btn btn-default" id="close">关闭窗口</a>                        
            </div>
        </div>
        <!-- /.modal-content -->
         <!-- modals -->
         <div id="v" class="easyui-window" title="分发记录" data-options="modal:true,closed:true" style="width:700px;height:500px;padding:15px;display:none;">
             <!-- gridview row -->
             <table id="dgff"></table>
             <!-- end gridview row -->
        </div>
        <!-- /.modal-content -->
    </div>
    <include file="Public/footer" />
    <script>
        $(document).ready(function() {
            //初始化页面
            $('#yjyjff').addClass('on');
            loaddg();
            LoadDDL('q_lqr','LQR');
            LoadDDL('q_sflq','SFLQ');
        });
        //加载数据列表
        function loaddg() {
            $('#dg').datagrid({
                loadMsg: '正在查询，请稍后...',
                title: '双击查看药剂申请明细',
                height: $(window).height() - 300,
                url: '{:U(\'queryyjyjff\')}',
                queryParams: {
                    lqr: $('#q_lqr').combobox('getValue'),
                    sflq: $('#q_sflq').combobox('getValue')
                },
                nowrap: false,
                striped: true,
                collapsible: false,
                loadMsg: '正在加载，请稍后。。。',
                remoteSort: false,
                singleSelect: true,
                pageSize: 100,
                idField: 'id',
                pagination: true,
                rownumbers: true,
                pagination: true,
                pageNumber: 1,
                pageSize: 20,
                pageList: [20, 40, 80, 160],
                fitColumns: true,
                columns: [
                    [{
                        field: 'lb',
                        title: '类别',
                        width: 100
                    }, {
                        field: 'lqr',
                        title: '领取人',
                        width: 100
                    }, {
                        field: 'sj',
                        title: '申请时间',
                        width: 100
                    }, {
                        field: 'sflq',
                        title: '是否领取',
                        width: 100
                    }, {
                        field: 'bz',
                        title: '备注',
                        width: 50
                    }, {
                        field: 'xq',
                        title: '操作',
                        width: 100,
                        formatter: function(value,row,index){
                        return '<a href="#" onclick="addffjl('+index+')" style="font-size:13px;color:green;">增加分发记录</a>';
                        }
                    }]
                ],
                onDblClickRow:function(index,row){
                    loadlqmx(row.id);
                    loadffmx(row.id);
                    document.getElementById("hidid").value = row.id;
                    $('#w').window('open');
                }
            });
            $("#querybtn").click(function() {
                $('#dg').datagrid('load', {
                    "lqr": $('#q_lqr').combobox('getValue'),
                    "sflq": $('#q_sflq').combobox('getValue')
                });
            });
        }

        //加载领取明细
        function loadlqmx(id){
            var html='';
            var option = {
                type: "POST",
                url: "{:U('queryyjyjlqmx')}",
                data: {id:id},
                success: function (data) {
                    for(var i=0;i<data.length;i++){
                        html+=' <tr><td>'+data[i].mc+'</td><td>'+data[i].jl+'</td><td>'+data[i].syjl+'</td></tr>';
                    }
                    $('#lqmx').html(html);
                }
            };
            $.ajax(option);
        }

        //加载分发明细
        function loadffmx(id){
            var html='';
            var option = {
                type: "POST",
                url: "{:U('queryyjyjffmx')}",
                data: {id:id},
                success: function (data) {
                    for(var i=0;i<data.length;i++){
                        html+='<div class="ffjl">'+data[i].sj+'领取 '+data[i].mc+' '+ data[i].jl+' L</div> ';
                    }
                    $('#jl').html(html);
                }
            };
            $.ajax(option);
        }

        //关闭窗口
        $('#close').click(function(){
            $('#w').window('close');
        })

        //退回整改
        $('#submits').click(function(){
            var id=document.getElementById("hidid").value;
            var option = {
                type: "POST",
                url: "{:U('setyjyjlqzt')}",
                data: {id:id},
                success: function (data) {
                    layer.closeAll();
                    layer.msg(data);
                    $('#w').window('close');
                    $("#querybtn").click();
                }
            };
            $.ajax(option);
        })

         //增加分发记录
         function addffjl(index){
            $('#dg').datagrid('selectRow', index);
            var row = $('#dg').datagrid('getSelected');
            if(row){
                $('#dgff').datagrid({
                loadMsg: '正在查询，请稍后...',
                title: '',
                // height: $(window).height() - 300,
                url: '{:U(\'queryyjyjlqmx\')}',
                queryParams: {
                    id: row.id
                },
                nowrap: false,
                striped: true,
                collapsible: false,
                loadMsg: '正在加载，请稍后。。。',
                remoteSort: false,
                singleSelect: true,
                pageSize: 100,
                idField: 'id',
                pagination: true,
                rownumbers: true,
                pagination: true,
                pageNumber: 1,
                pageSize: 20,
                pageList: [20, 40, 80, 160],
                fitColumns: true,
                onClickCell: onClickCell,
                columns: [
                    [{
                        field: 'id',
                        title: '领取明细ID',
                        hidden: true
                    },{
                        field: 'yjlqid',
                        title: '领取记录ID',
                        hidden: true
                    },{
                        field: 'mc',
                        title: '药剂名称',
                        width: 100
                    }, {
                        field: 'jl',
                        title: '领取剂量',
                        width: 100
                    }, {
                        field: 'syjl',
                        title: '剩余剂量',
                        width: 100
                    }, {
                        field: 'ffjl',
                        title: '分发剂量',
                        width: 100,
                        editor:{type:'numberbox',options:{precision:2}}
                    }, {
                        field: 'xq',
                        title: '操作',
                        width: 100,
                        formatter: function(value,row,index){
                        return '<a href="#" onclick="submit('+index+')" style="font-size:13px;color:green;">保存</a>';
                        }
                    }]
                ]
            });
                $('#v').window('open');
            }
            else{
                layer.msg('请选择需要添加分发记录的领取记录！');
            }
        }

        function submit(index){
            $('#dgff').datagrid('acceptChanges');
            $('#dgff').datagrid('selectRow', index);
            var row = $('#dgff').datagrid('getSelected');
            if(row){
                // alert(row.lqid);
                if(row.ffjl>row.syjl){
                    layer.msg('分发剂量大于剩余剂量！');
                    return false;
                }
                if(parseFloat(row.ffjl)<=0){
                    layer.msg('分发剂量不能为0');
                    return false;
                }
                //保存修改记录
                var option = {
                    type: "POST",
                    url: "{:U('addyjyjffjl')}",
                    data: {
                        lqmxid:row.id,
                        lqjlid:row.yjlqid,
                        mc:row.mc,
                        ffjl:row.ffjl,
                        syjl:row.syjl
                    },
                    success: function (data) {
                        layer.closeAll();
                        layer.msg(data);
                        $('#dgff').datagrid('load');
                    }
                };
                $.ajax(option);
            }
        }
    </script>
    <script type="text/javascript">
		$.extend($.fn.datagrid.methods, {
			editCell: function(jq,param){
				return jq.each(function(){
					var opts = $(this).datagrid('options');
					var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
					for(var i=0; i<fields.length; i++){
						var col = $(this).datagrid('getColumnOption', fields[i]);
						col.editor1 = col.editor;
						if (fields[i] != param.field){
							col.editor = null;
						}
					}
					$(this).datagrid('beginEdit', param.index);
					for(var i=0; i<fields.length; i++){
						var col = $(this).datagrid('getColumnOption', fields[i]);
						col.editor = col.editor1;
					}
				});
			}
		});
		
		var editIndex = undefined;
		function endEditing(){
			if (editIndex == undefined){return true}
			if ($('#dgff').datagrid('validateRow', editIndex)){
				$('#dgff').datagrid('endEdit', editIndex);
				editIndex = undefined;
				return true;
			} else {
				return false;
			}
		}
		function onClickCell(index, field){
			if (endEditing()){
				$('#dgff').datagrid('selectRow', index)
						.datagrid('editCell', {index:index,field:field});
				editIndex = index;
			}
		}
	</script>
</body>

</html>